
class RetCode:
    OK = 200      # 返回且无误
    ERROR = 222  # 返回但错误
    UNAUTHORIZED = 401  # 未登录
    EXCEPTION = 500     # 请求异常

# 订单委托类型
class OrderType:
    LMT = "LMT"  # 限价单
    MKT = "MKT"   # 市价单
    STP = "STP"
    STOP_LIMIT = "STOP_LIMIT"
    MIDPRICE = "MIDPRICE"


# 注意： 返回的订单数据，状态首字母会大写
class OrderStatus:
    # Indicates the order is not working, for instance if the order was invalid and triggered an error message,
    # or if the order was to short a security and shares have not yet been located.
    INACTIVE = "inactive"
    # Occurs most commonly if an exchange is closed.
    PENDING_SUBMIT = "pending_submit"
    """
    Indicates that a simulated order type has been accepted by the IBKR system and that this order has yet to be elected. 
    The order is held in the IBKR system until the election criteria are met.
    At that time the order is transmitted to the order destination as specified.
    """
    PRE_SUBMITTED = "pre_submitted"
    SUBMITTED = "submitted"     # Indicates that the order has been accepted at the order destination and is working.
    FILLED = "filled"   # Indicates that the order has been completely filled.
    PENDING_CANCEL = "pending_cancel"
    CANCELLED = "cancelled"
    WARN_STATE = "warn_state"
    SORT_BY_TIME = "sort_by_time"


# Asset class
class SecType:
    STK = "STK"     # stock
    OPT = "OPT"


# The side of the market of the order
class Side:
    BUY = "BUY"  # Buy contract near posted ask price
    SELL = "SELL"   # Sell contract near posted bid price
    ASSN = "ASSN"   # Option Assignment, if BUYSELL=BUY and OptionType=PUT or BUYSELL=SELL and OptionType=CALL
    EXER = "EXER"   # Option Exercise, if BUYSELL=SELL and OptionType=PUT or BUYSELL=BUY and OptionType=CALL


# The side of the market of the order.
class SideAbbr:
    B = "B"     # Buy contract near posted ask price
    S = "S"     # Sell contract near posted bid price
    X = "X"     # Option expired


class ContractType:
    OPEN = "1"   # 开仓
    CLOSE = "2"     # 平仓


# The Time-In-Force determines how long the order remains active on the market.
class TimeInForce:
    DAY = "DAY"   # if not executed a Day order will automatically cancel at the end of markets regular trading hours.
    GTC = "GTC"   # use Good-Till-Cancel for orders to remain active until it executes or cancelled.
    OPG = "OPG"   # use Open-Price-Guarantee for Limit-On-Open (LOO) or Market-On-Open (MOO) orders.
    IOC = "IOC"


# The Time-In-Force determines how long the order remains active on the market.
class ListingExchange:
    SMART = "SMART"   #
    SEHK = "SEHK"   #

